package cc.ilzy.mall.user.controller;

import cc.ilzy.mall.api.controller.IAddressController;
import cc.ilzy.mall.model.request.AddressAddRequest;
import cc.ilzy.mall.model.vo.AddressVo;
import cc.ilzy.mall.user.service.IAddressService;
import cc.ilzy.mall.utils.ApiResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class AddressController implements IAddressController {
    @Autowired
    private IAddressService addressService;

    @Override
    public ApiResponse<AddressVo> findAddressById(Long addressId) {
        AddressVo addressVo = addressService.findAddressById(addressId);
        return ApiResponse.success(addressVo);
    }

    @Override
    public ApiResponse<Void> add(AddressAddRequest addressRequest) {
        addressService.add(addressRequest);
        return ApiResponse.success("新增收货地址成功");
    }

    @Override
    public ApiResponse<Void> deleteAddress(Long addressId) {
        addressService.del(addressId);
        return ApiResponse.success("删除收货地址成功");
    }

    @Override
    public ApiResponse<List<AddressVo>> listAllAddress() {
        List<AddressVo> list = addressService.listAllAddress();
        return ApiResponse.success(list);
    }
}
